package com.test1;

import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class GameView extends SurfaceView implements SurfaceHolder.Callback, Runnable{
	private GameScene scene = null;
	private Thread mthread = null;
	private boolean bDraw = true;
	private long lasttime = 0;
	public GameView( GameScene scene ){
		super( Game.currentactivity );
		this.scene = scene;
		getHolder().addCallback( this );
		mthread = new Thread( this );
	}
	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		
	}
	
	public void surfaceCreated(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		bDraw = true;
		lasttime = System.currentTimeMillis();
		if( !mthread.isAlive() ){
			mthread.start();
		}
		Log.d("lijun", "createsurface");
	}
	
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		// TODO Auto-generated method stub
	}

	public void run(){
		while( bDraw ){
			Log.d( "lijun", "scene.run");
			scene.draw();
			scene.update( System.currentTimeMillis() - lasttime );
			lasttime = System.currentTimeMillis();
			try{
				Thread.sleep( 50 );
			}catch( Exception e ){
				e.printStackTrace();
			}
		}
	}
}